// kqmsn.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "msn.h"
#include <tchar.h>


#ifdef _MANAGED
#pragma managed(push, off)
#endif

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
		case DLL_PROCESS_DETACH:
			MyMSN::Release();
			break;
	}
    return TRUE;
}

int HandleCommand(TCHAR* cmd, int len) {
	TCHAR msn[MAX_PATH];
	TCHAR* id = cmd + 1;

	if (_tcsicmp(id, _T("show")) == 0) {
		MyMSN::GetMyMSN()->ShowWindow();
		return 0;
	}

	if (_tcsicmp(id, _T("login")) == 0) {
		MyMSN::GetMyMSN()->AutoSignin();
		return 0;
	}

	if (_tcsicmp(id, _T("logout")) == 0) {
		MyMSN::GetMyMSN()->Signout();
		return 0;
	}

	if (_tcsicmp(id, _T("reset")) == 0) {
		MyMSN::Release();
		return 0;
	}

	BOOL bOnlineOnly = TRUE;
	if (cmd[1] == _T('/')) {	/// include offline
		++id;
		bOnlineOnly = FALSE;
	}
	
	GetPrivateProfileString(_T("MSN"), id, _T(""), msn, MAX_PATH, _T(".\\kquick.ini"));

	if (_tcsicmp(msn, _T("")) == 0) {
		return -1;
	}

	MyMSN::GetMyMSN()->ShowContactWindow(msn, bOnlineOnly);

	return 0;
}

typedef int (*HANDLE_FUNC)(TCHAR*,int);

extern "C" __declspec(dllexport)
BOOL __cdecl Initialize(TCHAR (&cmdPrefix)[20], HANDLE_FUNC* pHandleFunc) {
	if (cmdPrefix) {
		cmdPrefix[0] = _T('/');
		cmdPrefix[1] = _T('\0');

		*pHandleFunc = HandleCommand;

		return TRUE;
	}

	return FALSE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

